var e = require("../../../@babel/runtime/helpers/interopRequireDefault").default,
  t = require("../../../@babel/runtime/helpers/objectSpread2"),
  n = require("../../../@babel/runtime/helpers/regeneratorRuntime"),
  a = require("../../../@babel/runtime/helpers/slicedToArray"),
  r = require("../../../@babel/runtime/helpers/asyncToGenerator"),
  i = require("../../../components/base/m-button/index"),
  d = require("../../../config/index"),
  o = require("../../../utils/index"),
  s = e(require("../behavior")),
  u = o.helper.publish;

function c(e) {
  return l.apply(this, arguments)
}

function l() {
  return (l = r(n().mark((function e(t) {
    var r, i, d, o, s, c, l, m, f, h, p, _, y, b, v, g, x, q, w, k;
    return n().wrap((function (e) {
      switch (e.prev = e.next) {
        case 0:
          return r = this.data.mode, e.next = 3, $.request[
            this.data.mode == 1 ? "GET/business/seek/rent/detail/" + this.data.uu_id : this.data.mode == 2 ? "GET/business/for/rent/detail/" + this.data.uu_id : "GET/business/recruit/worker/detail/" + this.data.uu_id]();
        case 3:
          i = e.sent, d = a(i, 1), 20002 === (o = d[0]).code ? (s = o.data, c = s.tel, l = s.description, m = s.leaseTerm, f = s.number, h = s.factoryYears, p = s.brand_id, _ = s.model_id, y = s.modelId, b = s.place, v = s.provinceId, g = s.cityId, x = s.latitude, q = s.longitude, w = s.payment_method, k = {
            address: b,
            city_id: g,
            city_text: s.cityText,
            latitude: x,
            longitude: q,
            province_id: v,
            province_text: s.provinceText
          }, this.selectComponent("#form").setValues({
            address: k,
            phone: c,
            description: l,
            detail: l,
            rent_days: s.number,
            wanted_num: s.leaseTerm,
            machine: {
              id: s.modelId,
              name: s.modelName
            },
            brand: p,
            model: _
          }), this.setData({
            factoryYearsValue: {
              id: h
            },
            machineValue: {
              id: s.modelId,
              name: s.modelName
            },
            payment_method: w
          })) : 14004 == o.code ? $.jxAlert({
            mode: "confirm",
            hideClose: !0,
            title: "温馨提示",
            content: o.msg,
            confirmText: "刷新信息"
          }).then((function () {
            u.reqInfoRefresh({
              mode: r,
              info: t
            }, !0)
          })).catch((function () {
            $.router.back()
          })) : $.jxAlert({
            content: o.msg
          });
        case 7:
        case "end":
          return e.stop()
      }
    }), e, this)
  })))).apply(this, arguments)
}
Page({
  useStore: function (e) {
    return {
      userInfo: e.storage.userInfo,
      machineConfig: e.global.machineConfig
    }
  },
  behaviors: [s.default],
  data: {
    mode: d.typeMode.seeking,
    recommendList: [],
    machineValue: null,
    factoryYearsList: d.factoryYears,
    factoryYearsValue: null,
    payment_method: ""
  },
  onLoad: function (e) {
    var t = this;
    return r(n().mark((function r() {
      var i, d, o, s, u;
      return n().wrap((function (n) {
        for (;;) switch (n.prev = n.next) {
          case 0:
            return n.next = 2;
          case 2:
            i = n.sent, t.selectComponent("#form").setValues({
              tel: wx.getStorageSync('userPhone')
            }), (u = e.uu_id) && (t.setData({
              uu_id: u
            }), c.call(t, u));
          case 9:
          case "end":
            return n.stop()
        }
      }), r)
    })))()
  },
  onSubmit: (0, i.apply)(r(n().mark((function e() {
    var a, r, i, d, o, s, c, l, m, f, h, p, _, y, b;
    return n().wrap((function (e) {
      switch (e.prev = e.next) {
        case 0:
          return e.next = 2, this.selectComponent("#form").verify({
            address: [{
              required: !0,
              message: "请选择施工地点"
            }],
            tel: [{
              required: !0,
              message: "请输入电话"
            }],
            machine: [{
              required: !0,
              message: "请选择机械类型"
            }]
          });
        case 2:
          if (r = e.sent) {
            e.next = 5;
            break
          }
          return e.abrupt("return", void $.msg("请输入验证码"));
        case 5:
          if (r.detail && !((null === (a = r.detail) || void 0 === a ? void 0 : a.length) < 5)) {
            e.next = 7;
            break
          }
          return e.abrupt("return", void $.msg("描述说明必须大于5个字符"));
        case 7:
          if (i = r.address, d = r.machine, o = r.brand, s = r.model, c = this.data, l = c.userInfo, m = c.factoryYearsValue, f = c.machineConfig, h = c.uu_id, p = c.payment_method, _ = c.mode, y = t(t({
              mode: 1,
              user_name: l.name
            }, i), {}, {
              phone: r.tel || "",
              modelId: (null == d ? void 0 : d.id) || "",
              modelName: (null == d ? void 0 : d.name) || "",
              factoryYears: (null == m ? void 0 : m.id) || "",
              description: r.detail || "",
              place: i.address,
              provinceId: i.province_id,
              cityId: i.city_id,
              number: r.wanted_num || "",
              leaseTerm: r.rent_days || "",
            }), !h) {
            e.next = 13;
            break
          }
          b = {
            phone: r.tel || "",
            number: r.wanted_num || "",
            leaseTerm: r.rent_days || "",
            description: r.detail || "",
            provinceId: i.province_id,
            cityId: i.city_id,
            provinceText: "",
            cityText: "",
            longitude: i.longitude,
            latitude: i.latitude,
            place: i.address,
            id: h,
            mode: 1,
            area: i.province_id,
            city: i.city_id,
            longitude: i.longitude,
            latitude: i.latitude,
            address: i,
          }, u.sendMachineInfo(y, h), e.next = 15;
          break;
        case 13:
          return e.next = 15, u.checkPayReleasePopup(_, (function (e) {
            e ? (y.pay_code = "10001", y.coin = f.push_consume_coin, u.sendMachineInfo(y)) : u.sendMachineInfo(y)
          }));
        case 15:
        case "end":
          return e.stop()
      }
    }), e, this)
  })))),
  onClickFactoryLabel: function (e) {
    var t = e.target.dataset.item,
      n = this.data.factoryYearsValue,
      a = n && n.id == t.id;
    this.setData({
      factoryYearsValue: a ? null : {
        id: t.id,
        name: t.name
      }
    })
  }
});